/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import com.bayu.services.entity.ExchangeCurrency;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Bayu
 */
@Repository("exchangeCurrencyDao")
@Transactional
public class ExchangeCurrencyImpl implements ExchangeCurrencyDao {
    private HibernateTemplate hibernateTemplate;
    SessionFactory sFac;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sFac = sessionFactory;
	hibernateTemplate = new HibernateTemplate(sessionFactory);
    }
    @Transactional(readOnly = false)
    public void save(ExchangeCurrency exchangeCurrency) {
        hibernateTemplate.saveOrUpdate(exchangeCurrency);
    }

    @Transactional(readOnly = false)
    public void delete(ExchangeCurrency exchangeCurrency) {
        hibernateTemplate.delete(exchangeCurrency);
    }

    @Transactional(readOnly = false)
    public void update(ExchangeCurrency exchangeCurrency) {
        hibernateTemplate.update(exchangeCurrency);
    }

    public List<ExchangeCurrency> getAll() {
        return hibernateTemplate.find("from ExchangeCurrency order by date asc");
    }

    public List<ExchangeCurrency> getAll(String query) {
        return hibernateTemplate.find(query);
    }

    public List<ExchangeCurrency> getById(Long id) {
        return hibernateTemplate.find("from ExchangeCurrency where id="+id);
    }

    public List<ExchangeCurrency> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from ExchangeCurrency where date between '"+start+"' and '"+end+"' order by date asc");
    }

    public List<ExchangeCurrency> getAllByMonth(String month) {
       return hibernateTemplate.find("from ExchangeCurrency where MONTH(date)='"+month+"' order by date asc");
       
    }

    public List custom(String query){
       return hibernateTemplate.find(query);

    }

}
